<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<!--Converted with LaTeX2HTML 96.1 (Feb 5, 1996) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds -->


<title>The 3n + 1 problem</title>
<meta name="description" content="The 3n + 1 problem">
<meta name="keywords" content="htmlatex">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<link rel="STYLESHEET" href="acm-00100_files/htmlatex.css">
</head><body bgcolor="#ffffff" lang="EN">
 <h1><br clear="all"><center><table bgcolor="#0060f0"><tbody><tr><td><b><font size="5" color="#c0ffff">&nbsp;<a name="SECTION0001000000000000000000">The 3<i>n</i> + 1 problem</a></font>&nbsp;</b></td></tr></tbody></table></center></h1>
<p>
</p><h2><font color="#0070e8"><a name="SECTION0001001000000000000000">Background</a></font></h2>
<p>
Problems in Computer Science are often classified as belonging to a
certain class of problems (e.g., NP, Unsolvable, Recursive).  In this
problem you will be analyzing a property of an algorithm whose
classification is not known for all possible inputs.
</p><p>
</p><h2><font color="#0070e8"><a name="SECTION0001002000000000000000">The Problem</a></font></h2>
<p>
Consider the following algorithm:
</p><pre><tt> 
		1. 		 input <i>n</i>
</tt><p>
<tt>		2. 		 print <i>n</i>
</tt></p><p>
<tt>		3. 		 if <i>n</i> = 1 then STOP
</tt></p><p>
<tt>		4. 		 		 if <i>n</i> is odd then  <img alt="tex2html_wrap_inline44" src="acm-00100_files/100img1.gif" width="95" align="middle" height="25"> 
</tt></p><p>
<tt>		5. 		 		 else  <img alt="tex2html_wrap_inline46" src="acm-00100_files/100img2.gif" width="74" align="middle" height="27"> 
</tt></p><p>
<tt>		6. 		 GOTO 2
</tt></p><p>
<tt></tt></p></pre>
<p>
Given the input 22, the following sequence of numbers will be printed
22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1
</p><p>
It is conjectured that the algorithm above will terminate (when a 1 is
printed) for any integral
input value.  Despite the simplicity of the algorithm,
it is unknown whether this conjecture is true.  It has been verified,
however, for all integers <i>n</i> such that 0 &lt; <i>n</i> &lt; 1,000,000 (and, in fact,
for many more numbers than this.)
</p><p>
Given an input <i>n</i>, it is possible to determine
the number of numbers printed (including
 the 1).  For a given <i>n</i> this is
called the <em>cycle-length</em> of <i>n</i>.  In the example above, the cycle
length of 22 is 16.
</p><p>
For any two numbers <i>i</i> and <i>j</i> you are to determine the maximum cycle
length over all numbers between <u> <i>i</i> and
<i>j</i>.
</u></p><p>
<u></u></p><h2><font color="#0070e8"><a name="SECTION0001003000000000000000">The Input</a></font></h2>
<p>
The input will consist of a series of pairs of integers <i>i</i> and <i>j</i>, one pair of
integers per line.  All integers will be less than 1,000,000 and greater
than 0.
</p><p>
You should process all pairs of integers and for each
pair determine the maximum cycle length over all integers between and
including <i>i</i> and <i>j</i>.
</p><p>You can assume that no operation overflows a 32-bit integer.
</p><p>
</p><h2><font color="#0070e8"><a name="SECTION0001004000000000000000">The Output</a></font></h2>
<p>
For each pair of input integers <i>i</i> and <i>j</i> you should output <i>i</i>, <i>j</i>,
and the maximum cycle length for integers between and including
<i>i</i> and <i>j</i>.  These three numbers
should be separated by at least one space with all three numbers on one
line and with one line of output for each line of input.  The integers
<i>i</i> and <i>j</i> must appear in the output in the same order in which they
appeared in the input and should be
followed by the maximum cycle length (on the same line).
</p><p>
</p><h2><font color="#0070e8"><a name="SECTION0001005000000000000000">Sample Input</a></font></h2>
<p>
</p><pre>1 10
100 200
201 210
900 1000
</pre>
<p>
</p><h2><font color="#0070e8"><a name="SECTION0001006000000000000000">Sample Output</a></font></h2>
<p>
</p><pre>1 10 20
100 200 125
201 210 89
900 1000 174
</pre>
<p>
</p></body></html>